package com.example.demo;

import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.ArrayList;
import java.util.List;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: 25228
 * Date: 2025-05-08
 * Time: 19:37
 */
@RestController
@RequestMapping("/message")
public class MessageController {
    private List<MessageInfo> messageInfoList=new ArrayList<>();

    @RequestMapping("/getList")
    public List<MessageInfo> getMessageInfoList(){
        return messageInfoList;
    }
    @RequestMapping(value = "/publish" , produces = "application/json")
    public String publish(@RequestBody MessageInfo messageInfo){
        System.out.println(messageInfo);
        if(!StringUtils.hasLength(messageInfo.getFrom())
           ||!StringUtils.hasLength(messageInfo.getMessage())
           ||!StringUtils.hasLength(messageInfo.getTo())){
            return "{\"ok\":0}";
        }
        messageInfoList.add(messageInfo);
        return "{\"ok\":1}";
    }
}